﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Vitruvian.Serialization;
using Vitruvian.Logging;
using Vitruvian.Testing;

namespace SpotItComponents
{
    [ContainsTests("Components.UserStuff")]
    [OptimisticSerialization]
    public class Session : Component
    {
        #region Private Data Members
        private Guid sessionKey = Guid.Empty;
        private UserAccount currentUser = null;
        private UserInfo userInfo = null;
        private DateTime lastInteraction = DateTime.Now;
        #endregion

        #region Constructors
        public Session()
        {
            sessionKey = Guid.NewGuid();
        }

        public Session(Guid key, UserAccount account)
        {
            sessionKey = key;
            currentUser = account;
            userInfo = new UserInfo(account);
        }

        public Session(Guid key, string playerName)
        {
            sessionKey = key;
            userInfo = new UserInfo(playerName);
        }
        #endregion

        #region Public Methods

        public void ActivityOccurred()
        {
            lastInteraction = DateTime.Now;
        }

        public TimeSpan InactiveTimeSpan
        {
            get
            {
                return DateTime.Now.Subtract(lastInteraction);
            }
        }

        [DontSerialize]
        public Guid SessionKey
        {
            get { return sessionKey; }
        }

        public virtual UserInfo UserInfo
        {
            get { return userInfo; }
            set { userInfo = value; }
        }

        #endregion
    }
}
